unit Inf_Maquina;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, Grids, DBGrids;

type
  TFrmInf_Maquina = class(TForm)
    Label1: TLabel;
    dbgrid: TDBGrid;
    BitBtn1: TBitBtn;
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure dbgridKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure dbgridDblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmInf_Maquina   : TFrmInf_Maquina;
  xinf_departamento: string;
  xinf_maquina     : string;

implementation

uses dm,db,dbtables,clsDepartamento,clsMaquina;

var departamento: TDepartamento;
    maquina     : TMaquina;
    tq          : TQuery;
    tds         : TDataSource;

{$R *.DFM}

procedure TFrmInf_Maquina.FormActivate(Sender: TObject);
begin
 departamento.Recuperar(xinf_departamento);
 label1.caption   := label1.caption+departamento.Dep_descricao;
 tq.databasename  := dmint.db.databasename;
 tq.active        := false;
 tds.dataset      := tq;
 dbgrid.datasource:= tds;
 maquina.Listar_Maquinas(xinf_departamento,tq);
end;

procedure TFrmInf_Maquina.FormCreate(Sender: TObject);
begin
 departamento:= TDepartamento.Create;
 maquina     := TMaquina.Create;
 tq          := TQuery.Create(self);
 tds         := TDataSource.Create(self);
end;

procedure TFrmInf_Maquina.FormDestroy(Sender: TObject);
begin
 departamento.free;
 maquina.free;
 tq.free;
 tds.free;
end;

procedure TFrmInf_Maquina.BitBtn1Click(Sender: TObject);
begin
 xinf_maquina:= tq.fieldbyname('Cod_Maquina').asstring;
 close;
end;

procedure TFrmInf_Maquina.dbgridKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=12 then BitBtn1Click(Sender);
end;

procedure TFrmInf_Maquina.dbgridDblClick(Sender: TObject);
begin
 BitBtn1Click(Sender);
end;

end.
